package sc.prototype.pfs.eventnotify.executor.impl;

import java.util.HashMap;

import javax.annotation.PostConstruct;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import sc.prototype.pfs.eventnotify.executor.NotifyExecutor;
import sc.prototype.pfs.eventnotify.executor.NotifyExecutorFactory;
import sc.prototype.pfs.eventnotify.model.Notice;
import sc.prototype.pfs.eventnotify.model.enums.NotifyAPIType;

public class DefaultNotifyExecutorFactory implements NotifyExecutorFactory {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    HashMap<NotifyAPIType, NotifyExecutor> executorMap;

    @PostConstruct
    public void init() {
        logger.info("通知方式执行器字典初始化完毕：{}", executorMap);
    }

    @Override
    public NotifyExecutor create(Notice notice) {
        NotifyAPIType type = notice.getNotifyTarget().getNotifyAPIType();
        if (type != null) {
            return executorMap.get(type);
        } else {
            String err = String.format("%s的通知方式为null！", notice.toShortString());
            throw new IllegalArgumentException(err);
        }
    }

    public void setExecutorMap(HashMap<NotifyAPIType, NotifyExecutor> executorMap) {
        this.executorMap = executorMap;
    }

}
